package com.koron.sinoprobe.web.ledger.controller;

import com.koron.bean.base.Response;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.sinoprobe.web.ledger.bean.query.SpProjectDeviceQuery;
import com.koron.sinoprobe.web.ledger.bean.query.SpStatisticsQuery;
import com.koron.sinoprobe.web.ledger.service.SpStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author jzp
 * @since 2022/5/24
 */
@RestController
@RequestMapping("/sp/statistics/")
@Api(tags = "专项统计")
public class SpStatisticsController {

    @Autowired
    private SpStatisticsService spStatisticsService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @GetMapping("/listSpTotal")
    @ApiOperation(value = "专项项目生产驾驶舱统计", notes = "total:年度专项总数; investment:专项总投资额; investmentProcess:投资进度; finishTotal:已完成数量; finishProcess:总完成比例; " +
            "totalA:A类专项总数; finishTotalA: A类专项已完成数量; finishProcessA: A类专项完成比例; B类同理; deptList: 部门专项完成比例")
    public Response<Map> listSpTotal(SpStatisticsQuery query) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), spStatisticsService, "listSpTotal", Map.class, query));
    }

    @PostMapping("/countByDeviceIds")
    @ApiOperation(value = "根据设备id集合查询数量")
    public Response<List<SpProjectDeviceQuery>> countByDeviceIds(@RequestBody List<SpProjectDeviceQuery> query) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), spStatisticsService, "countByDeviceIds", List.class, query));
    }

}
